package com.cgs.query.service

import com.cgs.query.domain.ExecutionObj
import com.cgs.query.domain.QueryDefine
import com.cgs.query.domain.QuerySource
import com.cgs.query.exception.QueryException

interface IQueryService {

    /***
     * 执行查询
     */
    fun execute(projectName: String, name: String, param: Map<String, Any?>?, timeout: Int?): Any?

    /**
     * 查询一组QuerySource
     * @name 项目名称list
     */
    fun findSourceByProjectNames(names: List<String>): QuerySourceMap

    /**
     * 查询QueryDefine 和 QuerySource
     */
    fun findDefineSourceByWholeNameAndProjectName(name: String, projectName: String): DefineSource

}

class DefineSource(
        val wholeName: String,
        val projectName: String,
        val queryDefine: QueryDefine?,
        val executionObj: ExecutionObj?,
        val querySource: QuerySource?
) {

    fun notNull() {
        if (querySource == null || executionObj == null) {
            throw QueryException("找不到定义[$projectName : $wholeName ]")
        }
    }
}

class QuerySourceMap(val map: Map<String, QuerySource?>)